package com.kgc.scd.consumer;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kgc.scd.bean.SearchHistory;
import com.kgc.scd.contant.SearchHistoryConstant;
import com.kgc.scd.mapper.SearchHistoryMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Wrapper;

/**
 * Created On : 2022/6/11.
 * <p>
 * Author     : hi
 * <p>
 * Description: 使用P2P模式，队列消息消费者
 */
@Slf4j
@RestController
public class SearchHistoryConsumer {

    @Autowired(required = false)
    private SearchHistoryMapper searchHistoryMapper;

    /**
     * 从指定队列中，消费消息，进行业务处理 添加
     */
    @JmsListener(destination = SearchHistoryConstant.Search_History_ADD_P2P)
    public void queueP2P(SearchHistory searchHistory){
    searchHistoryMapper.insert(searchHistory);

   }


    /**
     * 从指定队列中，消费消息，进行业务处理 删除
     */
    @JmsListener(destination = SearchHistoryConstant.Search_History_DEl_P2P)
    public void delP2P(String historyValue) {
        QueryWrapper<SearchHistory> searchHistoryQueryWrapper = new QueryWrapper<>();
        searchHistoryQueryWrapper.eq("history_value",historyValue);
        searchHistoryMapper.delete(searchHistoryQueryWrapper);
    }
}
